网页视频编码指南

您所在的位置:网站首页 您没有安装可用于执行video mp4类型文件的应用 网页视频编码指南

网页视频编码指南

2024-07-03 21:23| 来源: 网络整理| 查看: 265

目前在 Web 浏览器中通常没有任何无损(甚至接近无损)的视频编解码器。原因很简单:视频太大。根据定义,无损压缩不如有损压缩有效。例如,具有 4:2:0 色度二次采样的未压缩 1080p 视频(1920 x 1080 像素)至少需要 1.5 Gbps。使用诸如 FFV1(Web 浏览器不支持)之类的无损压缩可能会将其降低到 600 Mbps 左右,具体取决于内容。这仍然是每秒通过连接泵送的大量比特,并且目前对于任何实际使用都不实用。

即使某些有损编解码器具有可用的无损模式,情况也是如此;当前的任何网络浏览器都没有实现无损模式。你可以做的最好的事情是选择使用有损压缩的高质量编解码器并将其配置为执行尽可能少的压缩。一种方法是将编解码器配置为使用“快速”压缩,这本质上意味着实现的压缩更少。

在外部准备视频

要从你的网站或应用程序外部为存档目的准备视频,请使用对原始未压缩视频数据执行压缩的实用程序。例如,免费的 x264 实用程序可用于使用非常高的比特率对 AVC 格式的视频进行编码:

bashx264 --crf 18 -preset ultrafast --output outfilename.mp4 infile

虽然其他编解码器在大幅压缩视频时在最佳情况下可能能获得更好的质量,但通常这些编解码器的速度都很慢,因此,在总体质量相似的情况下,这种近乎无损的压缩方式要快很多。

录制视频

考虑到你可以获得多接近无损的限制,你可以考虑使用 AVC 或 AV1。例如,如果你使用 MediaStream Recording API 录制视频,则在创建 MediaRecorder 时可能会使用如下代码目的:

jsconst kbps = 1024; const Mbps = kbps * kbps; const options = { mimeType: 'video/webm; codecs="av01.2.19H.12.0.000.09.16.09.1, flac"', bitsPerSecond: 800 * Mbps, }; let recorder = new MediaRecorder(sourceStream, options);

此示例创建一个 12 位色彩及使用 4:4:4 色度二次采样的 BT.2100 HDR 配置,并且通过 FLAC 录制无损音频的 MediaRecorder。生成的文件的视频和音频轨道之间共享的比特率不超过 800Mbps。你可能需要根据硬件性能、需求和你选择使用的特定编解码器来调整这些值。这种比特率对于网络传输显然不现实,可能只在本地使用。

将 codecs 参数的值分解为其点描述的属性,我们看到以下内容:

Value Description av01 The four-character code (4CC) designation identifying the AV1 codec. 2 The profile. A value of 2 indicates the Professional profile. A value of 1 is the High profile, while a value of 0 would specify the Main profile. 19H The level and tier. This value comes from the table in section A.3 of the AV1 specification, and indicates the high tier of Level 6.3. 12 The color depth. This indicates 12 bits per component. Other possible values are 8 and 10, but 12 is the highest-accuracy color representation available in AV1. 0 The monochrome mode flag. If 1, then no chroma planes would be recorded, and all data should be strictly luma data, resulting in a greyscale image. We've specified 0 because we want color. 000 The chroma subsampling mode, taken from section 6.4.2 in the AV1 specification. A value of 000, combined with the monochrome mode value 0, indicates that we want 4:4:4 chroma subsampling, or no loss of color data. 09 The color primaries to use. This value comes from section 6.4.2 in the AV1 specification; 9 indicates that we want to use BT.2020 color, which is used for HDR. 16 The transfer characteristics to use. This comes from section 6.4.2 as well; 16 indicates that we want to use the characteristics for BT.2100 PQ color. 09 The matrix coefficients to use, from the section 6.4.2 again. A value of 9 specifies that we want to use BT.2020 with variable luminance; this is also known as BT.2010 YbCbCr. 1 The video "full range" flag. A value of 1 indicates that we want the full color range to be used.

你选择编解码器的文档可能会提供你在构建 codecs 参数时将使用的信息。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3